package com.yumeng.framework.persistence.mybatis.injector.methods;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * 删除全部
 * 测试用
 * @author wxd
 * @date 2021/9/22 16:43
 */
public class DeleteAll extends AbstractMethod {

    public DeleteAll() {
        super("deleteAll");
    }

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        //删除全表 仅支持演示表操作
        if (!tableInfo.getTableName().startsWith("demo_")){
            return null;
        }

        String sql = "delete from " + tableInfo.getTableName();
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        return this.addDeleteMappedStatement(mapperClass, sqlSource);
    }
}
